from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import sessionmaker

from configs.kb_config import SQLALCHEMY_DATABASE_URI
# from .custom import PydanticSession


engine = create_engine(
	SQLALCHEMY_DATABASE_URI,
	pool_size=30,  # 连接池中的连接数
	max_overflow=10,  # 超出连接池大小外最多创建的连接数
	pool_timeout=30,  # 连接池中获取连接的最大等待时间，单位为秒
	pool_recycle=600,  # 连接池中连接的最大存活时间，单位为秒
	pool_pre_ping=True,  # 启用预 ping 功能
	connect_args={
		"charset": "utf8mb4"
	}
)
print(f"engine: {engine.url}")

SessionLocal = sessionmaker(
	bind=engine,
	autocommit=False,
	autoflush=False,
	expire_on_commit=False,
	# class_=PydanticSession
)

Base = declarative_base()
